<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2020/10/31
  Time: 19:28
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()
            +":"+request.getServerPort()+path+"/";
    pageContext.setAttribute("basePath",basePath);
%>
<%--<script type="text/javascript" src="<%=basePath%>js/jquery-3.4.1.js"></script>
<script type="text/javascript" src="<%=basePath%>js/jQuery.easyui.js"></script>--%>

<script type="text/javascript" src="<%= request.getContextPath() %>/js/jquery-3.4.1.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
        //如你给出的地址可以这样
        var username = request("username");
        //如你给出的地址可以这样
        var olduserid = request("userId");
        $("#names").val(username);
        if (document.hidden !== undefined) {
            document.addEventListener('visibilitychange', () => {
                console.log(document.hidden);
                if(document.hidden){
                    console.log("离开标签了");
                }else {
                    console.log("回来了");
                    $.ajax({
                        url:"<%=basePath%>/getUser",
                        type:"post",
                        data:null,
                        dataType:"json",
                        success:function(data){
                            console.log("data:"+data.toString());
                            console.log("olduserid:"+olduserid);
                            console.log("newUerId:"+data.id);
                            var newUerId=data.id;
                            if(olduserid!=newUerId){
                                console.log("跳转");
                                window.location.href = "<%=basePath%>/login.jsp";
                            }
                        }
                    })
                }
            })
        }


    });

    function request(paras){
        var url = location.href;
        var paraString = url.substring(url.indexOf("?")+1,url.length).split("&");
        var paraObj = {}
        for (i=0; j=paraString[i]; i++){
            paraObj[j.substring(0,j.indexOf("=")).toLowerCase()] = j.substring(j.indexOf("=")+1,j.length);
        }
        var returnValue = paraObj[paras.toLowerCase()];
        if(typeof(returnValue)=="undefined"){
            return "";
        }else{
            return returnValue;
        }
    }
</script>
<html>
<head>
    <title>登陆成功页面</title>
</head>
<input type="text" name="userids"/>
<body>

<input type="text" name="names" id="names"/>
<br>
</body>
</html>
